"""
epoll IO多路复用方法
"""
from socket import *
from select import *

# 创建tcp套接字
from time import sleep

tcp = socket()
tcp.bind(("0.0.0.0",8888))
tcp.listen(5)

udp = socket(AF_INET,SOCK_DGRAM)

eq = epoll() #创建好epoll

# {fileno：object} 时刻与关注IO 保持一致
map = {tcp.fileno():tcp}

eq.register(tcp,EPOLLIN)  #关注IO
eq.register(udp,EPOLLOUT)  #关注IO
map[udp.fileno()] = udp #添加到字典

sleep(5)
print("开始监控IO 对象")
events = eq.poll()
print(events)
print(map[events[0][0]])

